--
-- DESCRIPTION
--
-- @COMPANY **
-- @AUTHOR **
-- @DATE ${date} ${time}
--

---@type BP_Pig_C
local M = UnLua.Class("Climber.Blueprints.Characters.BP_PlatformChar")

-- function M:Initialize(Initializer)
-- end

-- function M:UserConstructionScript()
-- end

function M:ReceiveBeginPlay()
    self.WallDetector.OnComponentBeginOverlap:Add(self, self.OnComponentBeginOverlap_WallDetector)

    UE.UKismetSystemLibrary.K2_SetTimerDelegate({ self, self.CheckLedge }, 0.25, true)
end

-- function M:ReceiveEndPlay()
-- end

-- function M:ReceiveTick(DeltaSeconds)
--     self.Super.ReceiveTick(self)
-- end

-- function M:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
-- end

-- function M:ReceiveActorBeginOverlap(OtherActor)
-- end

-- function M:ReceiveActorEndOverlap(OtherActor)
-- end

-- 墙面检测
function M:OnComponentBeginOverlap_WallDetector(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, FromSweep, SweepResult)
    self:RotateChar()
end

-- 旋转角色
function M:RotateChar()

    local NewRotation = UE.FRotator()

    NewRotation = UE.UKismetMathLibrary.ComposeRotators(self:K2_GetActorRotation(), UE.FRotator(0, 180, 0))

    self:K2_SetActorRotation(NewRotation, false)
end

-- 检测边缘
function M:CheckLedge()

    if self.CharacterMovement.CurrentFloor.bWalkableFloor then
        local OverlappingActors = UE.TArray(UE.AActor)

        self.LedgeDetector:GetOverlappingActors(OverlappingActors)

        if OverlappingActors:Length() == 0 then
            self:RotateChar()
        end
    end
end

-- 重写被击败
function M:Defeat()
    self.Super.Defeat(self)
    UE.UKismetSystemLibrary.K2_SetTimerDelegate({ self, self.K2_DestroyActor }, 3, false)
end

return M
